package com.xxcxcxcx.jobsystem.mixin.job.Brewmaster;

import com.xxcxcxcx.jobsystem.Main;
import com.xxcxcxcx.jobsystem.common.Job.Brewmaster.Brewmaster;
import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.TippedArrowRecipe;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import static com.xxcxcxcx.jobsystem.common.Job.Brewmaster.Brewmaster.*;

@Mixin(TippedArrowRecipe.class)
public class TippedArrowRecipeMixin {

    @Inject(method = "assemble(Lnet/minecraft/world/inventory/CraftingContainer;)Lnet/minecraft/world/item/ItemStack;", at = @At("RETURN"), cancellable = true)
    private void originsClasses$handleAdditionalPotionNbt(CraftingContainer inv, CallbackInfoReturnable<ItemStack> cir) {
        ItemStack result = cir.getReturnValue();
        if(!result.isEmpty()) {
            ItemStack input = inv.getItem(1 + inv.getWidth());
            if(input.hasTag()) {
                if(Brewmaster.hasPotionBonus(input)) {
                    int level = input.getOrCreateTagElement(Main.MOD_ID).getInt(Refining+RefiningLevel);
                    float time = input.getOrCreateTagElement(Main.MOD_ID).getFloat(Refining+Refiningtime);
                    int Glevel = input.getOrCreateTagElement(Main.MOD_ID).getInt(Refining);
                    String Creat = input.getOrCreateTagElement(Main.MOD_ID).getString(Refining+RefiningCreater);
                    cir.setReturnValue(Brewmaster.addPotionBonus(result,Creat,Glevel,level,time));
                }
            }
        }
    }

}
